<template>
	<view class="main">
		<u-line></u-line>
		<!-- 基本信息 -->
		<view class="psh_container">
			<view class="psh_basic" style="background-color: #FAFAFA;">
				<view class="basic_title" style="padding: 10px 10px 5px 10px;color: #333;font-weight: 800;font-size: 16px;">
					{{'排水户'}}
				</view>
				<view class="basic_info">
					<view class="info_item" v-for="(basic,indexBC) in pshBasicInfo" :key="indexBC">
						<!-- 横版 -->
						<view class="item_text" style="padding: 10px;display: flex;align-items: center;justify-content: space-between;" v-if="getBasicShow(indexBC)">
							<view class="text_left" id="text_tag">
								{{basic.name}}
							</view>
							<view class="text_right">
								<view class="text_a" v-if="basic.type==1"  @click="openPicker(basic)">
									<u--input v-model="basic.text" suffixIcon="arrow-down" readonly :placeholder="basic.tag" placeholderStyle="font-size:14px;color:rgb(192, 196, 204)" style="background-color: #FFF !important;"></u--input>
								</view>
								<view class="text_b" v-if="basic.type==2">
									<u--input v-model="basic.value" :placeholder="basic.tag" placeholderStyle="font-size:14px;color:rgb(192, 196, 204)" style="background-color: #FFF !important;"></u--input>
								</view>
							</view>
						</view>
						<!-- 竖版 -->
						<view class="item_text" style="padding: 10px;" v-if="!getBasicShow(indexBC)">
							<view class="text_left" id="text_tag">
								{{basic.name}}
							</view>
							<view class="text_right_line" style="margin-top: 8px;margin-left: -2px;">
								<view class="text_a" v-if="basic.type==1"  @click="openPicker(basic)">
									<u--input v-model="basic.text" suffixIcon="arrow-down" readonly :placeholder="basic.tag" placeholderStyle="font-size:14px;color:rgb(192, 196, 204)" style="background-color: #FFF !important;"></u--input>
								</view>
								<view class="text_b" v-if="basic.type==2">
									<u--input v-model="basic.value" :placeholder="basic.tag" placeholderStyle="font-size:14px;color:rgb(192, 196, 204)" style="background-color: #FFF !important;"></u--input>
								</view>
                <!--  图片-->
                <view class="be" v-if="basic.type==4"
                  style="border: 1px solid #ceccca;height: 72px;margin-top: 16px;display: flex;border-radius: 4px;">
                  <view class="aaa" style="display: flex;" v-for="(item,index) in fileTempList1" :key="index">
                    <view style="position: relative; margin-top: 8px; margin-left: 8px;">
                      <u--image :src="item.url" width="55px" height="55px"></u--image>
                      <u-icon name="close" style="position: absolute; top: 2px; right: 2px;"
                        @click="removeItem1(index)"></u-icon>
                    </view>
                  </view>
                  <u--image :src="upLoadUrl" @click="getFile1" v-show="fileTempList1.length<5" width="55px"
                    height="55px" style="margin-top: 8px;margin-left: 8px;"></u--image>
                </view>
							</view>
						</view>
						<u-line v-show="indexBC!=pshBasicInfo.length-1"></u-line>
					</view>
				</view>
			</view>
		</view>
		<!-- 基本信息选择器 -->
		<u-picker :show="basicShow" :columns="basicColumns" :defaultIndex=[basicIndex] keyName="text" closeOnClickOverlay @confirm="getValueBasicPicker" @cancel="closeBasicPicker()" @close="closeBasicPicker()"></u-picker>
		<u-gap height="15" bgColor="#FAFAFA"></u-gap>
		
		<!-- 许可证信息 -->
		<view class="permit" v-show="pshBasicInfo[11].value==1" style="background-color: #FFF">
			<view class="permit_title" style="padding: 10px;color: #333;font-weight: 800;font-size: 16px;">
				{{'许可证'}}
			</view>
			<view class="permit_list" v-show="permitList.length!=0">
				<view class="title_list_permit" style="display: flex;align-items: center;justify-content: space-between;color: #999;font-size: 14px;padding: 5px 10px 5px 10px;">
					<view class="a_title_list_permit">
						{{'许可证编号'}}
					</view>
					<view class="b_title_list_permit" style="margin-right: 5px;">
						{{'操 作'}}
					</view>
				</view>
				<view class="list_item_permit" v-for="(per,indexR) in permitList" :key="indexR">
					<view class="content_permit" style="display: flex;align-items: center;justify-content: space-between;padding: 10px;">
						<view class="id_permit" style="color: #333;font-size: 14px;">
							{{per[4].value}}
						</view>
						<view class="permit_right" style="display: flex;align-items: center;">
							<u-icon name="edit-pen" @click="editPermit(per)" size="20" style="margin-right: 5px;"></u-icon>
							<u-icon name="trash" @click="deletePermit(indexR)" size="20"></u-icon>
						</view>
					</view>
					<u-line v-show="indexR!=permitList.length-1"></u-line>
				</view>
			</view>
			<view class="permit_add" style="padding: 10px;display: flex;align-items: center;justify-content: center;">
				<view class="add_one" style="display: flex;align-items: center;padding-bottom: 5px;" @click="openAddPermit()">
					<u-icon name="plus-circle" color="#FF5000" size="18" style="margin-top: 3px;margin-right: 5px;"></u-icon>
					<view class="add_tag" style="font-size: 16px;color: #FF5000;">{{'新增许可证'}}</view>
				</view>
			</view>
			<u-gap height="15" bgColor="#FAFAFA"></u-gap>
		</view>
		
		<!-- 许可证模态框 -->
		<u-overlay :show="permitEditShow" style="display: flex;align-items: center;justify-content: center;">
			<view class="edit_permit_container" style="width: 93vw;height: auto;max-height: 80vh;min-height:30vh;background-color: #FAFAFA;border-radius: 10px;padding-top: 10px;display: flex;flex-direction: column;justify-content: center;">
				<view class="epc_title" style="text-align: center;font-size: 18px;color: #333;margin-bottom: 10px;">
					{{permitTitle}}
				</view>
				<view class="epc_list" style="overflow-y: auto;">
					<view class="list_item" v-for="(permit,indexPer) in addTempPermit" :key="indexPer">
						<view class="epc_b" style="padding: 15px 10px 0px 10px;">
							<view class="a_left" id="text_tag">
								{{permit.name}}
							</view>
							<view class="b_right" style="margin-top: 8px;margin-left: -2px;">
								<view class="text_a" v-if="permit.type==1"  @click="openPickerPermit(permit)">
									<u--input v-model="permit.text" suffixIcon="arrow-down" readonly :placeholder="permit.tag" placeholderStyle="font-size:14px;color:rgb(192, 196, 204)" style="background-color: #FFF !important;"></u--input>
								</view>
								<view class="text_b" v-if="permit.type==2">
									<u--input v-model="permit.value" :placeholder="permit.tag" placeholderStyle="font-size:14px;color:rgb(192, 196, 204)" style="background-color: #FFF !important;"></u--input>
								</view>
								<view class="text_c" v-if="permit.type==3"  @click="openPickerPermitDate(permit,indexPer)">
									<u--input v-model="permit.text" suffixIcon="arrow-down" readonly :placeholder="permit.tag" placeholderStyle="font-size:14px;color:rgb(192, 196, 204)" style="background-color: #FFF !important;"></u--input>
								</view>
                <!--  图片-->
                <view class="be" v-if="permit.type==4"
                  style="border: 1px solid #ceccca;height: 72px;margin-top: 16px;display: flex;border-radius: 4px;">
                  <view class="aaa" style="display: flex;" v-for="(item,index) in fileTempList" :key="index">
                    <view style="position: relative; margin-top: 8px; margin-left: 8px;">
                      <u--image :src="item.url" width="55px" height="55px"></u--image>
                      <u-icon name="close" style="position: absolute; top: 2px; right: 2px;"
                        @click="removeItem(index)"></u-icon>
                    </view>
                  </view>
                  <u--image :src="upLoadUrl" @click="getFile" v-show="fileTempList.length<5" width="55px"
                    height="55px" style="margin-top: 8px;margin-left: 8px;"></u--image>
                </view>

							</view>
						</view>
					</view>
					<u-gap height="10" bgColor="#FAFAFA"></u-gap>
				</view>
				
				<view class="permit_btn" style="display: flex;align-items: center;justify-content: space-around;border-top: 1px solid #d6d7d9;margin-top: 2px;">
					<view class="close"  @click="permitEditShow = false" style="width: 50%;height: 32px;text-align: center;border-right: 1px solid #d6d7d9;padding-top: 7px;color: #666;">
						{{'取 消'}}
					</view>
					<view class="confirm" @click="editPermitPush()" style="width: 50%;height: 32px;text-align: center;padding-top: 7px;color: #FFF;background-color: #FF5000;border-radius: 0px 0px 10px 0px;">
						{{'确 认'}}
					</view>
				</view>
			</view>
		</u-overlay>
		
		<!-- 许可证时间选择器 -->
		<u-datetime-picker
			ref="datePicker"
			:show="permitShowDate"
			:minDate="23558400000"
			:maxDate="4102329600000"
			mode="date" 
			:title="permitTitleDate"
			closeOnClickOverlay
			@close="permitShowDate=false"
			@cancel="permitShowDate=false"
			@confirm="setDateTime()"
		></u-datetime-picker>
		<!-- 许可证基本选择器 -->
		<u-picker :show="permitShowBasic" :columns="permitColumns" :defaultIndex=[permitIndex] keyName="text" closeOnClickOverlay @confirm="getValuePermitPicker" @cancel="closePermitPicker()" @close="closePermitPicker()"></u-picker>
		
		<!-- 排口信息 -->
		<view class="out" style="background-color: #FFF">
			<view class="out_title" style="padding: 10px;color: #333;font-weight: 800;font-size: 16px;">
				{{'排口（非必填）'}}
			</view>
			<view class="out_list" v-show="outList.length!=0">
				<view class="title_list_out" style="display: flex;align-items: center;justify-content: space-between;color: #999;font-size: 14px;padding: 5px 10px 5px 10px;">
					<view class="a_title_list_out">
						{{'排口编号'}}
					</view>
					<view class="b_title_list_out" style="margin-right: 5px;">
						{{'操 作'}}
					</view>
				</view>
				<view class="list_item_out" v-for="(out,indexO) in outList" :key="indexO">
					<view class="content_out" style="display: flex;align-items: center;justify-content: space-between;padding: 10px;">
						<view class="id_out" style="color: #333;font-size: 14px;">
							{{out[1].value}}
						</view>
						<view class="out_right" style="display: flex;align-items: center;">
							<u-icon name="edit-pen" @click="editOut(out)" size="20" style="margin-right: 5px;"></u-icon>
							<u-icon name="trash" @click="deleteOut(indexO)" size="20"></u-icon>
						</view>
					</view>
					<u-line v-show="indexO!=outList.length-1"></u-line>
				</view>
			</view>
			<view class="out_add" style="padding: 10px;display: flex;align-items: center;justify-content: center;">
				<view class="add_one" style="display: flex;align-items: center;padding-bottom: 5px;" @click="openAddOut()">
					<u-icon name="plus-circle" color="#FF5000" size="18" style="margin-top: 3px;margin-right: 5px;"></u-icon>
					<view class="add_tag" style="font-size: 16px;color: #FF5000;">{{'新增排口'}}</view>
				</view>
			</view>
		</view>
		<!-- 排口模态框 -->
		<u-overlay :show="outEditShow" style="display: flex;align-items: center;justify-content: center;">
			<view class="edit_out_container" style="width: 93vw;height: auto;max-height: 80vh;min-height:30vh;background-color: #FAFAFA;border-radius: 10px;padding-top: 10px;display: flex;flex-direction: column;justify-content: center;">
				<view class="out_title" style="text-align: center;font-size: 16px;color: #333;margin-bottom: 10px;">
					{{outTitle}}
				</view>
				<view class="out_list" style="overflow-y: auto;">
					<view class="list_item" v-for="(outx,indexOX) in outAddTemp" :key="indexOX">
						<view class="out_b" style="padding: 15px 10px 0px 10px;">
							<view class="a_left" id="text_tag">
								{{outx.name}}
							</view>
							<view class="b_right" style="margin-top: 8px;margin-left: -2px;">
								<view class="text_a" v-if="outx.type==1"  @click="openPickerOut(outx)">
									<u--input v-model="outx.text" suffixIcon="arrow-down" readonly :placeholder="outx.tag" placeholderStyle="font-size:14px;color:rgb(192, 196, 204)" style="background-color: #FFF !important;"></u--input>
								</view>
								<view class="text_b" v-if="outx.type==2">
									<u--input v-model="outx.value" :placeholder="outx.tag" placeholderStyle="font-size:14px;color:rgb(192, 196, 204)" style="background-color: #FFF !important;"></u--input>
								</view>
							</view>
						</view>
					</view>
					<u-gap height="10" bgColor="#FAFAFA"></u-gap>
				</view>
				
				<view class="permit_btn" style="display: flex;align-items: center;justify-content: space-around;border-top: 1px solid #d6d7d9;margin-top: 2px;">
					<view class="close"  @click="outEditShow = false" style="width: 50%;height: 32px;text-align: center;border-right: 1px solid #d6d7d9;padding-top: 7px;color: #666;">
						{{'取 消'}}
					</view>
					<view class="confirm" @click="editOutPush()" style="width: 50%;height: 32px;text-align: center;padding-top: 7px;color: #FFF;background-color: #FF5000;border-radius: 0px 0px 10px 0px;">
						{{'确 认'}}
					</view>
				</view>
			</view>
		</u-overlay>
		<!-- 排口基本选择器 -->
		<u-picker :show="outPickerShow" :columns="outColumns" :defaultIndex=[outIndex] keyName="text" closeOnClickOverlay @confirm="getValueOutPicker" @cancel="closeOutPicker()" @close="closeOutPicker()"></u-picker>
		<u-gap height="15" bgColor="#FAFAFA"></u-gap>
		
		<!-- 操作按钮 -->
		<view class="btns" style="padding: 0px 10px;">
			<u-button @click="pushPshContent" text="确 认" color="#FF5000" style="border-radius: 4px;"></u-button>
			<u-button @click="backMeIndex" text="取 消" style="border-radius: 4px;margin-top: 10px;"></u-button>
		</view>
		
		<!-- 验证码模态框 -->
		<u-modal :show="codeShow" title="输入验证码" confirmText="提 交" cancelText="取 消" showCancelButton confirmColor="#FF5500" buttonReverse closeOnClickOverlay @confirm="submitPshData()" @close="closeCodeModal()" @cancel="closeCodeModal()" :asyncClose="true">
			<view class="code_content" style="display: flex;align-items: center;justify-content: center;padding: 15px 0px;">
				<view class="a_code">
					<u-input placeholder="请输入验证码" v-model="query.code">
						<u-icon slot="prefix" size="16" :name="codeUrl"></u-icon>
					</u-input>
				</view>
				<view class="b_code" style="border-radius: 4px;height: 37px;background-color: #f3f4f6;">
					<img :src="codeSrc" @click="replaceCode()" style="height: 37px;width: 92px;"/>
				</view>
			</view>
		</u-modal>
		
		<u-gap height="15" bgColor="#FAFAFA"></u-gap>
	</view>
</template>

<script>
  import croods from '@/common/croods-1.3.3.js';
  window.croods = croods;
  window.hydra = require('../../../common/wst_hydra-1.0.0.js');
	import { getCode,submitPsh,uploadFile } from '@/common/api.js'
	export default {
		onLoad: function(option) {

		},
		onShow() {

		},
		onUnload() {

		},
		data() {
			return {
				/* 基本信息 */
				pshBasicInfo: [{
						id: 1,
						name: '重要性',
						code: 'aqfl',
						must: true,
						value: 0,
						text: '',
						type: 1,
						tag:'请选择重要性'
					},
					{
						id: 2,
						name: '管理部门',
						code: 'dept',
						must: true,
						value: '',
						text:'',
						type: 1,
						tag:'请选择管理部门'
					},
					{
						id: 3,
						name: '排水等级',
						code: 'djfl',
						must: true,
						value: '',
						text: '',
						type: 1,
						tag:'请选择排水等级'
					},
					{
						id: 4,
						name: '法定负责人',
						code: 'frxm',
						must: true,
						value: '',
						type: 2,
						tag:'请输入法人姓名'
					},
					{
						id: 5,
						name: '行业分类',
						code: 'hyfl',
						must: true,
						value: '',
						text: '',
						type: 1,
						tag:'请选择行业分类'
					},
					{
						id: 6,
						name: '联系方式',
						code: 'lxfs',
						must: true,
						value: '',
						type: 2,
						tag:'请输入联系方式'
					},
					{
						id: 7,
						name: '联系人',
						code: 'lxr',
						must: true,
						value: '',
						type: 2,
						tag:'请输入联系人'
					},
					{
						id: 8,
						name: '排水户地址',
						code: 'pshdz',
						must: true,
						value: '',
						type: 2,
						tag:'请输入排水户地址'
					},
					{
						id: 9,
						name: '排水户名称',
						code: 'pshmc',
						must: true,
						value: '',
						type: 2,
						tag:'请输入排水户名称'
					},
					{
						id: 10,
						name: '排污许可证编号',
						code: 'pwxkzbh',
						must: false,
						value: '',
						type: 2,
						tag:'请输入排污许可证编号（非必填）'
					},
					{
						id: 11,
						name: '统一社会信用代码',
						code: 'tyshxydm',
						must: true,
						value: '',
						type: 2,
						tag:'请输入统一社会信用代码'
					},
					{
						id: 12,
						name: '有无许可证',
						code: 'ywxkz',
						must: true,
						value: 2,
						text: '',
						type: 1,
						tag:'请选择是否有许可证'
					},
          {
            id: 13,
            name: '图片采集',
            code: 'fj',
            must: false,
            value: '',
            type: 4,
            tag:'请上传图片'
          },
				],
				basicShow:false,
				basicColumns:[],
				basicIndex:0,
				upLoadUrl: require("@/static/icons/xjyw/add.png"),
        /* 许可证图片暂存列表 */
        fileTempList: [],
        fileTempList1: [],
				/* 许可证信息 */
				permitInfo:[{
						id: 1,
						name: '发证机关',
						code: 'fzjgmc',
						must: true,
						value: '',
						text: '',
						type: 2,
						tag:'请输入发证机关'
					},{
						id: 2,
						name: '发证日期',
						code: 'fzrq',
						must: true,
						value: '',
						text: '',
						type: 3,
						tag:'请选择发证日期'
					},{
						id: 3,
						name: '重点排水户',
						code: 'lrzdpsh',
						must: true,
						value: 2,
						text: '',
						type: 1,
						tag:'请选择是否为重点排水户'
					},{
						id: 4,
						name: '排水户名称',
						code: 'pshmc',
						must: true,
						value: '',
						text: '',
						type: 2,
						tag:'请输入排水户名称'
					},{
						id: 5,
						name: '许可证编号',
						code: 'xkzbh',
						must: true,
						value: '',
						text: '',
						type: 2,
						tag:'请输入许可证编号'
					},{
						id: 6,
						name: '许可证有效期起始日',
						code: 'xkzyxqqssj',
						must: true,
						value: '',
						text: '',
						type: 3,
						tag:'请选择许可证有效期开始时间'
					},{
						id: 7,
						name: '许可证有效期截止日',
						code: 'xkzyxqjssj',
						must: true,
						value: '',
						text: '',
						type: 3,
						tag:'请选择许可证有效期结束时间'
					},{
						id: 8,
						name: '详细地址',
						code: 'xxdz',
						must: true,
						value: '',
						text: '',
						type: 2,
						tag:'请输入详细地址'
					},{
						id: 9,
						name: '一级排水户名称',
						code: 'yjpshmc',
						must: false,
						value: '',
						text: '',
						type: 2,
						tag:'请输入一级排水户名称（非必填）'
					},{
						id: 10,
						name: '排放标准',
						code: 'zywrwjpfbz',
						must: false,
						value: '',
						text: '',
						type: 2,
						tag:'请输入主要污染物及排放标准（非必填）'
					},{
            id: 11,
            name: '许可证电子原件',
            code: 'fj',
            must: false,
            value: '',
            text: '',
            type: 4,
            tag:'请上传许可证电子原件'
          }
				],
				permitShowBasic:false,
				permitShowDate:false,
				permitTitleDate:'',
				permitIndexDate:null,
				permitColumns:[],
				permitIndex:0,
				permitEditShow:false,
				addTempPermit:[],
				permitList:[],
				permitTitle:'新增许可证',
				isAddPermit:false,
				
				/* 排口信息 */
				outInfo:[{
						id: 1,
						name: '连接管位置',
						code: 'ljgwz',
						must: true,
						value: '',
						text: '',
						type: 2,
						tag:'请输入连接管位置（道路）'
					},{
						id: 2,
						name: '排口编号',
						code: 'pkbh',
						must: true,
						value: '',
						text: '',
						type: 2,
						tag:'请输入排口编号'
					},{
						id: 3,
						name: '排口类型',
						code: 'pklx',
						must: true,
						value: '',
						text: '',
						type: 1,
						tag:'请选择排口类型'
					},{
						id: 4,
						name: '排水井编号',
						code: 'psjbh',
						must: true,
						value: '',
						text: '',
						type: 2,
						tag:'请输入排水井编号'
					},{
						id: 5,
						name: '排水量（m³/日）',
						code: 'psl',
						must: true,
						value: null,
						text: '',
						type: 2,
						tag:'请输入排水量（m³/日）'
					},{
						id: 6,
						name: '最终去向',
						code: 'pszzqx',
						must: true,
						value: '',
						text: '',
						type: 2,
						tag:'请输入排水量最终去向'
					},{
            id: 7,
            name: '管径(mm)',
            code: 'gj',
            must: false,
            value: '',
            text: '',
            type: 2,
            tag:'请输入管径(mm)'
          },{
            id: 8,
            name: '排水规律',
            code: 'psgl',
            must: false,
            value: '',
            text: '',
            type: 2,
            tag:'请输入排水规律'
          },{
            id: 9,
            name: '许可证编号',
            code: 'xkzbh',
            must: false,
            value: '',
            text: '',
            type: 2,
            tag:'请输入许可证编号'
          }
				],
				outList:[],
				outAddTemp:[],
				outEditShow:false,
				outTitle:'新增排口',
				isAddOut:false,
				outPickerShow:false,
				outColumns:[],
				outIndex:0,
				
				/* 请求数据组装 */
				query:{
					code:'',
					entity:null,
					key:'',
					licences:[],
					outlets:[]
				},
				
				/* 验证码 */
				codeUrl:require('@/static/assets/code.png'),
				codeShow:false,
				codeSrc:'',
				loading: false
				
				
			}
		},
		methods: {
			/* 基本信息方法 */
			getBasicShow(num){
				let validNums = [0, 1, 2, 3, 4, 5, 6, 11,]
				return validNums.includes(num)
			},
			openPicker(basic){
				switch(basic.id){
					case 1 :
						this.basicColumns = [[
							{value:1,text:'重点排水户',index:0},
							{value:2,text:'非重点排水户',index:0}
						]]
						basic.value == 0 ? this.basicIndex=0 : basic.value == 1 ? this.basicIndex=0 : this.basicIndex=1
						break
					case 2 :
						let data2 = [
							{value: '340272', text: '三山经济开发区',index:1},
							{value: '340271', text: '经济技术开发区',index:1},
							{value: '340223', text: '南陵县',index:1},
							{value: '340212', text: '繁昌区',index:1},
							{value: '340210', text: '湾沚区',index:1},
							{value: '340209', text: '弋江区',index:1},
							{value: '340207', text: '鸠江区',index:1},
							{value: '340202', text: '镜湖区',index:1},
							{value: '340201', text: '市辖区',index:1},
							{value: '340281', text: '无为市',index:1}
						]
						this.basicColumns = [data2]
						if(basic.value==''){
							this.basicIndex = 0
						}else{
							this.basicIndex = data2.findIndex(zoo => zoo.value==basic.value)
						}
						break
					case 3 :
						let data3 = [
							{value:'First',text:'一级',index:2},
							{value:'Second',text:'二级',index:2}
						]
						this.basicColumns = [data3]
						if(basic.value==''){
							this.basicIndex = 0
						}else{
							this.basicIndex = data3.findIndex(zoo => zoo.value==basic.value)
						}
						break
					case 5 :
						let data5 = [
						    {value: '01',text: '工业类',index:4},
						    {value: '02',text: '建筑类',index:4},
						    {value: '03',text: '餐饮类',index:4},
						    {value: '04',text: '医疗类',index:4},
						    {value: '05',text: '机关事业单位类',index:4},
						    {value: '06',text: '汽修机洗类',index:4},
						    {value: '07',text: '洗涤类',index:4},
						    {value: '08',text: '垃圾收集处理类',index:4},
						    {value: '09',text: '农贸市场类',index:4},
						    {value: '10',text: '畜牧养殖类',index:4},
						    {value: '11',text: '综合商业类',index:4},
						    {value: '12',text: '居民类',index:4}
						]
						this.basicColumns = [data5]
						if(basic.value==''){
							this.basicIndex = 0
						}else{
							this.basicIndex = data5.findIndex(zoo => zoo.value==basic.value)
						}
						break
					case 12 :
						this.basicColumns = [[
							{value:1,text:'有',index:11},
							{value:0,text:'无',index:11}
						]]
						basic.value == 2 ? this.basicIndex=0 : basic.value == 1 ? this.basicIndex=0 : this.basicIndex=1
						break
				}
				this.basicShow = true
			},
			closeBasicPicker(){
				this.basicShow = false
				this.basicColumns = []
			},
			getValueBasicPicker(e){
				let data = e.value[0]				
				this.pshBasicInfo[data.index].value = data.value
				this.pshBasicInfo[data.index].text = data.text
				this.basicShow = false
			},
			
			/* 许可证方法 */
			formatDateTime(inputTime) {
				if (inputTime) {
					let offset = inputTime.getTimezoneOffset() * 60000
					let localTime = new Date(inputTime.getTime() - offset)
					return localTime.toISOString().slice(0, 10)
				}
			},
			getTimestamp(date){
				let temp = new Date(date.replace(/-/g, '/'))
				return temp.getTime()
			},
			openAddPermit(){
				this.addTempPermit = []
				this.permitTitle = '新增许可证'
				this.isAddPermit = true
				this.addTempPermit = JSON.parse(JSON.stringify(this.permitInfo))
				this.permitEditShow = true
			},
			openPickerPermit(permit){
				this.permitColumns = [[
					{value:1,text:'重点排水户',index:2},
					{value:0,text:'非重点排水户',index:2}
				]]
				permit.value == 2 ? this.permitIndex=0 : permit.value == 1 ? this.permitIndex=0 : this.permitIndex=1
				this.permitShowBasic = true
			},
			getValuePermitPicker(e){
				let data = e.value[0]
				this.addTempPermit[data.index].value = data.value
				this.addTempPermit[data.index].text = data.text
				this.permitShowBasic = false
			},
			closePermitPicker(){
				this.permitShowBasic = false
				this.permitColumns = []
			},
			openPickerPermitDate(permit,num){
				this.permitIndexDate = num
				let dateStamp = 0
				if(permit.value==''){
					let date = new Date()
					dateStamp = date.getTime()
				}else{
					dateStamp = this.getTimestamp(permit.value)
				}
				this.$refs.datePicker.innerValue = dateStamp
				this.permitTitleDate = permit.name
				this.permitShowDate = true
			},
			setDateTime(){
				this.addTempPermit[this.permitIndexDate].value = this.formatDateTime(new Date(this.$refs.datePicker.innerValue))
				this.addTempPermit[this.permitIndexDate].text = this.formatDateTime(new Date(this.$refs.datePicker.innerValue))
				this.permitShowDate = false
			},
			async editPermitPush(){
				for (let item of this.addTempPermit) {
					if(item.must){
						if(item.id!=3 && item.value==''){
							uni.$u.toast(`${item.name}不能为空，请补充`)
							return
						}
						if(item.id==3 && item.value==2){
							uni.$u.toast('是否为重点排水户不能为空，请补充')
							return
						}
					}
				}
				let start = this.getTimestamp(this.addTempPermit[5].value)
				let end = this.getTimestamp(this.addTempPermit[6].value)
				if(end < start){
					uni.$u.toast('许可证起始日期与截止日期冲突，请核对')
					return
				}
				if(this.isAddPermit){
					this.permitList.push(this.addTempPermit)
				}
        // 上传图片
        let fj = await this.getIds()
        this.permitInfo.find(item => item.code == 'fj').value = fj
				this.permitEditShow = false
				this.isAddPermit = false
			},
			editPermit(per){
				this.permitTitle = '编辑许可证'
				this.addTempPermit = per
				this.permitEditShow = true
			},
			deletePermit(index){
				let that = this
				uni.showModal({
					title: '您确定要删除这个许可证吗？',
					success: function (res) {
						if (res.confirm) {
							that.permitList.splice(index,1)
						}
					}
				})
			},
			/* 排口方法 */
			openAddOut(){
				this.outAddTemp = []
				this.outTitle = '新增排口'
				this.isAddOut = true
				this.outAddTemp = JSON.parse(JSON.stringify(this.outInfo))
				this.outEditShow = true
			},
			isNum(value){
				return !isNaN(parseFloat(value)) && isFinite(value)
			},
			editOutPush(){
				for (let item of this.outAddTemp) {
					if(item.must){
						if(item.id!=5 && item.value==''){
							uni.$u.toast(`${item.name}不能为空，请补充`)
							return
						}
						if(item.id==5){
							if(item.value==null){
								uni.$u.toast('排水量不能为空，请补充')
								return
							}
							if(!this.isNum(item.value)){
								uni.$u.toast('排水量仅允许输入数字，请核对')
								return
							}
						}
					}
          if(item.id==7&&item.value&&!this.isNum(item.value)) {
            uni.$u.toast('管径仅允许输入数字，请核对')
            return
          }
				}
				if(this.isAddOut){
					this.outList.push(this.outAddTemp)
				}
				this.outEditShow = false
				this.isAddOut = false
			},
			openPickerOut(outx){
				this.outColumns = [[
					{value:'雨水',text:'雨水',index:2},
					{value:'污水',text:'污水',index:2}
				]]
				outx.value == '' ? this.outIndex=0 : outx.value == '雨水' ? this.outIndex=0 : this.outIndex=1
				this.outPickerShow = true
			},
			getValueOutPicker(e){
				let data = e.value[0]
				this.outAddTemp[data.index].value = data.value
				this.outAddTemp[data.index].text = data.text
				this.outPickerShow = false
			},
			closeOutPicker(){
				this.outPickerShow = false
				this.outColumns = []
			},
			editOut(out){
				this.outTitle = '编辑排口'
				this.outAddTemp = out
				this.outEditShow = true
			},
			deleteOut(index){
				let that = this
				uni.showModal({
					title: '您确定要删除这个排口吗？',
					success: function (res) {
						if (res.confirm) {
							that.outList.splice(index,1)
						}
					}
				})
			},
			async pushPshContent(){
        const fj = await this.getIds(1)
        this.pshBasicInfo.find(item => item.code == 'fj').value = fj
				for (let item of this.pshBasicInfo) {
					if(item.must){
						if(item.type==2 && item.value==''){
							uni.$u.toast(`${item.name}不能为空，请补充`)
							return
						}
						if(item.type==1){
							if((item.id==2 || item.id==3 || item.id==5) && item.value==''){
								uni.$u.toast(`${item.name}不能为空，请补充`)
								return
							}
							if(item.id==1 && item.value==0){
								uni.$u.toast(`${item.name}不能为空，请补充`)
								return
							}
							if(item.id==12 && item.value==2){
								uni.$u.toast(`${item.name}不能为空，请补充`)
								return
							}
						}
					}
				}
				let reg = /^1[3-9]\d{9}$/
				if(!reg.test(this.pshBasicInfo[5].value)){
					uni.$u.toast('联系方式格式错误，请核对')
					return
				}
				/* 数据组装 */
				let basicEntity = this.pshBasicInfo.reduce((obj, item) => {
				    obj[item.code] = item.value
				    return obj
				}, {})
				this.query.entity = basicEntity
				if(this.pshBasicInfo[11].value!=0 && this.permitList.length!=0){
					this.permitList.forEach(per => {
						let perEntity = per.reduce((obj, item) => {
							if(item.id ==2 || item.id==6 || item.id==7){
								obj[item.code] = item.value + ' 00:00:00'
							}else{
								obj[item.code] = item.value
							}
							return obj
						}, {})
						this.query.licences.push(perEntity)
					})
				}
				if(this.outList.length!=0){
					this.outList.forEach(out => {
						let outEntity = out.reduce((obj, item) => {
							if(item.code=='psl'){
								obj[item.code] = Number(item.value)
							}else{
								obj[item.code] = item.value
							}
							return obj
						}, {})
						this.query.outlets.push(outEntity)
					})
				}
				getCode().then(res => {
					this.query.key = res.key
					this.codeSrc = res.codeUrl
					this.codeShow = true
				})
			},
			backMeIndex(){
				uni.navigateBack({
					delta: 1
				})
			},
			closeCodeModal(){
				this.query = {
					code:'',
					entity:null,
					key:'',
					licences:[],
					outlets:[]
				}
				this.codeShow = false
			},
			replaceCode(){
				getCode().then(res => {
					this.query.key = res.key
					this.codeSrc = res.codeUrl
					this.query.code = ''
				})
			},
			submitPshData(){
        if(this.loading) {
          return
        }
				if(this.query.code==''){
					uni.$u.toast('验证码不能为空，请补充')
					return
				}
				let regex = /^[A-Za-z0-9]{4}$/
				if(!regex.test(this.query.code)){
					uni.$u.toast('验证码格式错误，请核对')
					return
				}
        this.loading = true
				submitPsh(this.query).then(res => {
					if(res.code=='200'){
						this.codeShow = false
						uni.$u.toast(res.msg)
						setTimeout(function() {
							uni.navigateBack({
								delta: 1
							})
						}, 1000)
					}else if(res.code=='1075' || res.code=='1073'){
						uni.$u.toast(res.msg)
						this.query.code = ''
					}else{						
						uni.$u.toast(res.msg)
						this.codeShow = false
					}
				}).finally(() => {
          this.loading = false
        })
			},
      /* 图片上传 */
      getFile() {
      	let that = this
      	window.croods.customPlugin({
      		action: 'ServicePermissionPlugin.uploadMaterial',
      		params: {
      			reason: "获取相机、文件权限",
      			imgCount: "1",
      			uploadTitle: "请选择上传方式",
      			uploadType: "4",
      		},
      		success: function(res) {
      			let tfile = res.files[0]
      			if (res.flag) {
      				let temp = tfile.file.replace(/[\r\n]/g, "")
      				let url = 'data:' + tfile.type + ';base64,' + temp
      				tfile.url = url
      				that.fileTempList.push(tfile)
      			} else {
      				that.$u.toast('格式错误，上传失败');
      			}
      		},
      		fail: function(msg) {
      			if (msg != null || msg != undefined) {
      				that.$u.toast(msg);
      			} else {
      				that.$u.toast('照片上传失败');
      			}
      		}
      	});
      },
      removeItem(index) {
      	this.fileTempList.splice(index, 1);
      },
      getFile1() {
      	let that = this
      	window.croods.customPlugin({
      		action: 'ServicePermissionPlugin.uploadMaterial',
      		params: {
      			reason: "获取相机、文件权限",
      			imgCount: "1",
      			uploadTitle: "请选择上传方式",
      			uploadType: "4",
      		},
      		success: function(res) {
      			let tfile = res.files[0]
      			if (res.flag) {
      				let temp = tfile.file.replace(/[\r\n]/g, "")
      				let url = 'data:' + tfile.type + ';base64,' + temp
      				tfile.url = url
      				that.fileTempList1.push(tfile)
      			} else {
      				that.$u.toast('格式错误，上传失败');
      			}
      		},
      		fail: function(msg) {
      			if (msg != null || msg != undefined) {
      				that.$u.toast(msg);
      			} else {
      				that.$u.toast('照片上传失败');
      			}
      		}
      	});
      },
      removeItem1(index) {
      	this.fileTempList1.splice(index, 1);
      },
      async getIds(type) {
        const fileList = type ? this.fileTempList1 : this.fileTempList
      	let that = this
      	let fj = '';
      	let promises = fileList.map(async item => {
      		let temp = {
      			bizType: "app",
      			file: item.file,
      			fileName: item.name,
      			fileType: item.type
      		}
      		let res = await uploadFile(temp);
      		if (res != undefined || res != null) {
      			fj += res.id + ';'
      		}
      	})
      	await Promise.all(promises);
      	return fj;
      },
		}
	}
</script>

<style scoped>
	uni-page-body {
		height: 100% !important;
	}

	.main {
		height: 100%;
	}
	#text_tag {
		font-size: 14px;
		color: #888;
	}
	.text_right >>> .u-input{
		padding: 3px 5px !important;
		width: 160px !important;
	}
</style>